<!doctype html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=yes">
<title>商城登录</title>
<link rel="stylesheet" type="text/css" href="../static/css/jquery.mobile-1.4.5.min.css">
<link rel="stylesheet" type="text/css" href="../static/css/my.css">
<script type="text/javascript" src="../static/js/jquery-2.0.0.min.js"></script>
<script type="text/javascript" src="../static/js/jquery.mobile-1.4.5.min.js"></script>
<script type="text/javascript" src="../static/js/myinit.js"></script>
</head>

<body>
<div data-role="page" id="home">
	<div role="main" class="ui-content" style="padding:1em">
		<h1 style="text-align:center">请支付</h1>
		<button class="ui-btn ui-btn-corner-all" style="margin-top:250px" id="cmf">确认支付</button>
	</div>
	 
</div>
<script type="text/javascript">
	var code = getUrldata('code');
	var orderid=getUrldata('ORDERID');
	function initorder(){
		var url = '/webserver/api/v1/orderitem/?format=json&order='+orderid;
		$.getJSON(url,function(rs){
			var object = rs.objects[0];
			var order = object.order;
			if(order.status=='已下单'){
				
				zhifu();
				
			}
		
		},'json');
	}
	
	
	
 
	 
	
	
	$(document).on('pageshow','#home',function(){
		initorder();
		
	});
	$('#cmf').click(function(){
		initorder();
	});
	
	
	function zhifu(){
		var url="/weixin/getpayparm/";
		$.post(url,{"orderid":orderid},function(aa){
			if (typeof WeixinJSBridge == "undefined"){
				if( document.addEventListener ){
					document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
				}else if (document.attachEvent){
					document.attachEvent('WeixinJSBridgeReady', onBridgeReady); 
					document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
				}
			}else{
				onBridgeReady(aa);
			}
		}, "json");
	}
	
	function onBridgeReady(aa){
			
			 
			WeixinJSBridge.invoke('getBrandWCPayRequest', {
				"appId" : aa.appId,     //公众号名称，由商户传入     
				"timeStamp" : aa.timeStamp+"",         //时间戳，自1970年以来的秒数     
				"nonceStr"  :  aa.nonceStr, //随机串     
				"package"  :  aa.package,
				"signType"  :  aa.signType,         //微信签名方式 : 
				"paySign"  :  aa.paySign //微信签名 
			},
			function(res){     
				if(res.err_msg == "get_brand_wcpay_request:ok" ) {
				 
					toastwithaction('支付成功',function(){
						WeixinJSBridge.call('closeWindow');
					});
				}
				
			});
		}
	




</script>
</body>
</html>
